package com.study.sbsummary.controller;

import com.study.sbsummary.model.User;
import com.study.sbsummary.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/listAll")
    public List<User> getAllUser() {
        List<User> users = userService.listUsers();
        return users;
    }

    @GetMapping("/get")
    public User getById(@RequestParam("id") Long id) {
        User user = userService.selectUserById(id);
        return user;
    }

    @PostMapping("/add")
    public Boolean insert(User user) {
        boolean b = userService.addUser(user);
        return b;
    }

    @PostMapping("/delById")
    public Boolean delete(@RequestParam("id") Long id) {
        boolean b = userService.deleteUser(id);
        return b;
    }

    @PostMapping("/update")
    public Boolean update(@RequestBody User user) {
        boolean b = userService.updateUser(user);
        return b;
    }
}
